package com.meichis.yndms.vm;

import android.text.TextUtils;

import androidx.lifecycle.MutableLiveData;

import com.meichis.mcsappframework.utils.DateUtil;
import com.meichis.mcsappframework.utils.MessageTools;
import com.meichis.yndms.model.DataTable;
import com.meichis.yndms.model.Staff;
import com.meichis.yndms.model.TallyPhotos;
import com.meichis.yndms.model.TallyPhotosTypeSub;
import com.meichis.yndms.repository.manager.TallyPhotosManager;

import java.util.ArrayList;
import java.util.List;

public class TallyPhotosVM extends MyViewModel {

    private MutableLiveData<List<Staff>> staffList;
    private MutableLiveData<Staff> staff;
    private MutableLiveData<String> tallyDate;
    private MutableLiveData<DataTable> type;

    private List<DataTable> typeList;
    private MutableLiveData<TallyPhotosTypeSub> subType;
    private MutableLiveData<List<TallyPhotosTypeSub>> subList;
    private MutableLiveData<List<TallyPhotos>> photoList;

    public MutableLiveData<String> getTallyDate() {
        if (tallyDate == null) {
            tallyDate = new MutableLiveData<>();
            tallyDate.setValue(DateUtil.getCurDateStr(DateUtil.FORMAT_YMD));
        }
        return tallyDate;
    }


    public MutableLiveData<Staff> getStaff() {
        if (staff == null) {
            staff = new MutableLiveData<>();
        }
        return staff;
    }

    public MutableLiveData<List<Staff>> getStaffList() {
        if (staffList == null) {
            staffList = new MutableLiveData<>();
        }
        return staffList;
    }

    public void queryStaffList() {
        TallyPhotosManager.getInstance().GetStaffList(getShowDialog(), getUserInfo().getValue().getOrgId(), getStaffList());
    }


    public MutableLiveData<DataTable> getType() {
        if (type == null) {
            type = new MutableLiveData<>();
            type.setValue(getTypeList().get(0));
        }
        return type;
    }

    public List<DataTable> getTypeList() {
        if (typeList == null) {
            typeList = new ArrayList<>();
            //时间维度：0今日 1昨日 2本周 3本月
            typeList.add(new DataTable(0, "全部"));
            typeList.add(new DataTable(0, "理货"));
            typeList.add(new DataTable(0, "冰柜"));
        }
        return typeList;
    }

    public MutableLiveData<TallyPhotosTypeSub> getSubType() {
        if (subType == null) {
            subType = new MutableLiveData<>();
        }
        return subType;
    }

    public MutableLiveData<List<TallyPhotosTypeSub>> getSubList() {
        if (subList == null) {
            subList = new MutableLiveData<>();
        }
        return subList;
    }

    public void querySubTypeList() {
        TallyPhotosManager.getInstance().getSubTypeList(getShowDialog(),
                getUserInfo().getValue().getId(),
                getUserInfo().getValue().getOrgId(),
                getSubList());
    }


    public MutableLiveData<List<TallyPhotos>> getPhotoList() {
        if (photoList == null) {
            photoList = new MutableLiveData<>();
        }
        return photoList;
    }

    public void queryTallyPhotos() {
        if (getStaff().getValue().getDMSID() == null || TextUtils.isEmpty(getStaff().getValue().getDMSID())) {
            MessageTools.showLongToast("请选择业务员");
            return;
        }
        TallyPhotosManager.getInstance().getTallyPhotos(getShowDialog(),
                getStaff().getValue().getDMSID(),
                getUserInfo().getValue().getOrgId(),
                getType().getValue().getName(),
                getSubType().getValue().getPhotoTypeName(),
                getTallyDate().getValue(),
                getPhotoList());
    }
}
